package com.example.mybatis_study.controller;

import com.example.mybatis_study.mapper.ArticleMapper;
import com.example.mybatis_study.model.Articleinfo;
import com.example.mybatis_study.model.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {

    private static final Map map = new HashMap<>();

    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping("/queryAll")
    public Object queryAll() {
        return articleMapper.all();
    }

    @RequestMapping("/queryById")
    public Object queryById(Integer id) {

        return articleMapper.queryById(id);
    }


    @RequestMapping("/add")
    public Object add(Articleinfo articleinfo) {
        int num = articleMapper.add(articleinfo);
        return map;
    }

    @RequestMapping("/modify")
    public Object modify(Articleinfo articleinfo){
        int num = articleMapper.modify(articleinfo);
        return map;
    }

    @RequestMapping("/del")
    public Object del(Integer id){
        int num = articleMapper.del(id);
        return map;
    }

    @RequestMapping("/querySort")
    public Object querySort(String col, String sortBy) {
        return articleMapper.querySort(col, sortBy);
    }


    @RequestMapping("/queryArticleWithUser")
    public Object queryArticleWithUser(){
        return articleMapper.queryArticleWithUser();
    }
}
